//
//  lianxixinViewController.m
//  BAOASystem
//
//  Created by michael on 2018/2/22.
//  Copyright © 2018年 czd. All rights reserved.
//
#import "LXSegmentBtnView.h"
#import "shoujianViewController.h"
#import "fajianViewController.h"
#import "lianxixinViewController.h"
#import "gongyingViewController.h"
@interface lianxixinViewController ()<LXSegmentBtnViewDelegate>{
    shoujianViewController *_oneVC;
    fajianViewController *_twoVC;
//    gongyingViewController *_twoVC;

}
@property (nonatomic , strong) LXSegmentBtnView *segmentView1;

@end

@implementation lianxixinViewController

- (void)viewDidLoad {
    [super viewDidLoad];
         NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:

[UIColor whiteColor],NSForegroundColorAttributeName, nil];
 
[self.navigationController.navigationBar setTitleTextAttributes:attributes];
 self.navigationController.navigationBar.barTintColor = [UIColor colorWithHexString:@"0a62ea"];
   _segmentView1 = [[LXSegmentBtnView alloc] init];
        _segmentView1.delegate = self;
        _segmentView1.btnBackgroundSelectColor = [UIColor colorWithHexString:@"fbf2f2"];
        _segmentView1.titleFont = [UIFont systemFontOfSize:14];
self.segmentView1.frame =CGRectMake ((KScreenWidth - 200)/2,  40, 200, 30);;
    self.segmentView1.btnTitleArray = @[NSLocalizedString(@"联系人-收件箱", nil),NSLocalizedString(@"联系人-发件箱", nil)];
        self.navigationItem.titleView = _segmentView1;
__block typeof(self) bself = self;

    self.segmentView1.lxSegmentBtnSelectIndexBlock = ^(NSInteger index) {
        NSLog(@"block , index = %zd" , index);
        if(index ==0){
     [bself replaceFromOldViewController:_twoVC toNewViewController:_oneVC];

//          [bself.view addSubview:_oneVC.view];
//            [_twoVC.view removeFromSuperview];
        }
        if(index ==1){
//          [bself.view addSubview:_twoVC.view];
//            [_oneVC.view removeFromSuperview];
            [bself replaceFromOldViewController:_oneVC toNewViewController:_twoVC];

        }
    };
    
    self.view.backgroundColor = [UIColor whiteColor];
        _oneVC = [[shoujianViewController alloc] init];
//    _oneVC.view.backgroundColor = [UIColor redColor];
    _twoVC = [[fajianViewController alloc] init];
//    _twoVC.view.backgroundColor = [UIColor grayColor];
[self addChildViewController:_oneVC];
    [self addChildViewController:_twoVC];
  self.currentVC = _oneVC;
    [self.view addSubview:_oneVC.view];
    // Do any additional setup after loading the view.
}
- (void)replaceFromOldViewController:(UIViewController *)oldVc toNewViewController:(UIViewController *)newVc{
    /**
     *  transitionFromViewController:toViewController:duration:options:animations:completion:
     *  fromViewController    当前显示在父视图控制器中的子视图控制器
     *  toViewController        将要显示的姿势图控制器
     *  duration                动画时间(这个属性,old friend 了 O(∩_∩)O)
     *  options              动画效果(渐变,从下往上等等,具体查看API)UIViewAnimationOptionTransitionCrossDissolve
     *  animations            转换过程中得动画
     *  completion            转换完成
     */
    [self addChildViewController:newVc];
    [self transitionFromViewController:oldVc toViewController:newVc duration:0.1 options:UIViewAnimationOptionTransitionCrossDissolve animations:nil completion:^(BOOL finished) {
        if (finished) {
            [newVc didMoveToParentViewController:self];
            [oldVc willMoveToParentViewController:nil];
            [oldVc removeFromParentViewController];
            self.currentVC = newVc;
        }else{
            self.currentVC = oldVc;
        }
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
